package org.demo.warehouse.common.exception;

import lombok.extern.slf4j.Slf4j;
import org.demo.warehouse.common.utils.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author ZGC
 * @date 2019-6-25
 **/
@Slf4j
@ControllerAdvice
public class BusinessExceptionHandler {

    private static final String TOPIC_ID = "exception";

    private static final String SYSTEM_NAME = "warehouse-manager";

    @ResponseBody
    @ExceptionHandler(BusinessException.class)
    public R businessExceptionHandler(BusinessException e){
        log.warn("{}",e.getMessage());
        return R.failed(e.getMessage());
    }

    @ResponseBody
    @ExceptionHandler
    public R otherExceptionHandler(RuntimeException e) {
        log.error("{}",e);
        return R.failed(e.getMessage());
    }
}
